package com.bix.util.blizfiles.m2;

import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * This is a representation of a color that includes an alpha channel.
 *
 * @author squid
 *
 */
public class M2Color {
	private Log log = LogFactory.getLog (M2Color.class);
	
	class Components {
		private	float	red;
		private	float	green;
		private	float	blue;
		
		public void read (ByteBuffer bb) {
			this.red = bb.getFloat ();
			this.green = bb.getFloat ();
			this.blue = bb.getFloat ();
		}

		/**
		 * @return the red
		 */
		public float getRed() {
			return red;
		}

		/**
		 * @return the green
		 */
		public float getGreen() {
			return green;
		}

		/**
		 * @return the blue
		 */
		public float getBlue() {
			return blue;
		}
	}
	
	private	Components	components = new Components ();
	
	//
	// 0 = Transparent, 0xFFFF = Opaque.
	//
	private	short	alpha;
	
	public M2Color () {
	}
	
	public M2Color (ByteBuffer bb) {
		read (bb);
	}
	
	public void read (ByteBuffer bb) {
		this.components.read(bb);
		this.alpha = bb.getShort ();

		log.debug ("  Red[" + this.getComponents ().getRed () + "]");
		log.debug ("  Green[" + this.getComponents ().getGreen () + "]");
		log.debug ("  Blue[" + this.getComponents ().getBlue () + "]");
		log.debug ("  Alpha[" + this.getAlpha () + "]");
	}

	/**
	 * @return the color
	 */
	public Components getComponents() {
		return components;
	}

	/**
	 * @return the alpha
	 */
	public short getAlpha() {
		return alpha;
	}
	
	public boolean isTransparent () {
		return alpha == 0;
	}
	
	public boolean isOpaque () {
		return alpha == 0xFFFF;
	}
}
